package com.yuji.aacar.controller.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yuji.aacar.R;
import com.yuji.aacar.bean.beans.Car;
import com.yuji.aacar.core.cores.fres.CoreImageLoader;
import com.yuji.aacar.widgets.textview.PingFangTextView;

import java.util.ArrayList;


public class CarManagerAdapter extends BaseAdapter {


    private Context context;
    private ArrayList<Car> list;

    public CarManagerAdapter(Context context,ArrayList<Car > list){
        this.context=context;
        this.list=list;
    }

    public void updateData(ArrayList<Car > list){
        this.list=list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null? 0:list.size();
    }
    @Override
    public Object getItem(int position) {
        return list == null? 0:list.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.activity_car_manage_item,null);
            viewHolder=new ViewHolder();
            viewHolder.itemText= (PingFangTextView) convertView.findViewById(R.id.car_manage_tv);
            viewHolder.itemImage= (SimpleDraweeView) convertView.findViewById(R.id.car_manage_iv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        Car car = list.get(position);
        viewHolder.itemText.setText(car.getBrandName()+" "+car.getSeriesName());
        CoreImageLoader.loadImage(viewHolder.itemImage, list.get(position).getBrandUrl());
        return convertView;
    }
    public static  class ViewHolder{
        PingFangTextView itemText;
        SimpleDraweeView itemImage;
    }
}
